package controller;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import model.MyEllipse;
import model.MyPosition;
import model.MyRectangle;
import model.TypeImage;
import view.interfaces.IEditShape;

public class ControllerEditShape implements ActionListener {

		private IEditShape view;
		private String[] shapesAvailable = { "Rectangle", "Ellipse" };

	    public ControllerEditShape() {

	            
	    }

	    public void setView(IEditShape viewEntry) {
	            
	        this.view = viewEntry;
	        
	    }

	    public IEditShape getView() {
	            
	        return view;
	            
	    }

		@Override
		public void actionPerformed(ActionEvent e) {

			String action = e.getActionCommand();

	    	if(action.startsWith("EDITSHAPE")) {

	    		if(view.getShapeToEdit().getClass().toString().contains("MyRectangle")) {

	    			try {

	    				ControllerHome.image.editShape(
	    						view.getShapeToEditId(), 
	    						new MyRectangle(0, 
	    							new MyPosition(view.getValueTxtFieldPositionX(), 
	    									view.getValueTxtFieldPositionY()
	    							), 
	    							view.getValueTxtFieldWidth(), 
	    							view.getValueTxtFieldHeight(),
	    							new TypeImage<Color>(view.getValueComboBoxColorFilling(), view.getValueComboBoxColorOutline()),
	    							view.getValueTxtFieldBorderSize(),
	    							view.getValueIsIronWire()
	    						)
	    				);
	    				
	    			}
	    			catch (Exception ex) {
	    				
	    				JOptionPane.showMessageDialog(null, "Vous avez omis une dimension !");
	    				
	    			}
	    			
	    		}
	    		else if(view.getShapeToEdit().getClass().toString().contains("MyEllipse")) {

	    			try {

	    				ControllerHome.image.editShape(
	    						view.getShapeToEditId(), 
	    						new MyEllipse(0, 
	    							new MyPosition(view.getValueTxtFieldPositionX(), 
	    								view.getValueTxtFieldPositionY()
	    							), 
	    							view.getValueTxtFieldWidth(), 
	    							view.getValueTxtFieldHeight(),
	    							new TypeImage<Color>(view.getValueComboBoxColorFilling(), view.getValueComboBoxColorOutline()),
	    							view.getValueTxtFieldBorderSize(),
	    							view.getValueIsIronWire()
	    						)
	    				);
	    		
	    			}
	    			catch (Exception ex) {
	    				
	    				JOptionPane.showMessageDialog(null, "Vous avez omis une dimension !");
	    				
	    			}
	    		
	    		}
	    		
	    		view.hideWindowEditShape();
	    		
	    	}

		}
		
	}